# _*_ coding: utf-8 _*_
from odoo import models, api, fields
import odoo.addons.decimal_precision as dp


class OLHRExpenseExtend(models.Model):
    _inherit = "hr.expense"

    total_taxes = fields.Float(string='Tax', store=True, compute='_compute_amount', digits=dp.get_precision('Account'))
    payment_date = fields.Datetime(string='Payment Date', copy=False)

    @api.depends('quantity', 'unit_amount', 'tax_ids', 'currency_id')
    def _compute_amount(self):
        for expense in self:
            expense.untaxed_amount = expense.unit_amount * expense.quantity
            taxes = expense.tax_ids.compute_all(expense.unit_amount, expense.currency_id, expense.quantity,
                                                expense.product_id, expense.employee_id.user_id.partner_id)
            expense.total_amount = taxes.get('total_included')
            expense.total_taxes = taxes.get('total_included') - taxes.get('total_excluded')


class OLHRExpenseSheetExtend(models.Model):
    _inherit = "hr.expense.sheet"

    @api.multi
    def set_to_paid(self):
        self.write({'state': 'done'})
        for expense in self.expense_line_ids:
            expense.write({'payment_date': fields.Datetime.now()})
